<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>用户列表</title>
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../static/js/app.js"></script>
		<script src="../../static/js/eleDel.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/common/optUtils.js"></script>
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../lib/layui/css/layui.css">
		<link rel="stylesheet" href="../../lib/layui/css/layui.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
	</head>

	<body>
	<div class="weadmin-body">
		<div class="layui-row">
			<form class="layui-form layui-col-md12 we-search" id="FirstForm">
				<div class="layui-inline">
					<label class="layui-form-label">用户名:</label>
					<input id="username" type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">手机号</label>
					<input type="text" name="mobile" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">账号可用</label>
					<div class="layui-input-inline">
						<select name="enabled">
							<option value="">请选择</option>
							<option value="0">可用</option>
							<option value="1">禁用</option>
						</select>
					</div>

				<button id="search1" class="layui-btn" data-type="reload"><i class="layui-icon">&#xe615;</i>查询</button>
				</div>
			</form>
		</div>
		</div>
		<!--<div class="weadmin-block">
			<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
			<button class="layui-btn" onclick="WeAdminShow('添加用户','./add.html')"><i class="layui-icon"></i>添加</button>
		</div>-->
	<div class="layui-btn-group demoTable">
		<button class="layui-btn" data-type="delBatch"><i class="layui-icon"></i>批量删除</button>
		<button class="layui-btn" data-type="addEle"><i class="layui-icon"></i>添加</button>
	</div>
		<table class="layui-table" id="maintable" lay-filter="demo"></table>
		<script>
			var requrl=global.api_url + '/sysUser/selectAll'; //数据接口
			//var requrl=global.api_url + '/sysProvince/getProLists';
			layui.use(['table','jquery','form'], function(){
				var table = layui.table,$=layui.jquery,form = layui.form;
				//第一个实例
				table.render({
					elem: '#maintable'
					,url:  requrl
					,id:'table1'
					,toolbar: true
					,headers:{content_type: "application/json;charset=UTF-8",Authorization:getUser().token}
					,method:'post'
					,request: {
						pageName: 'current' //页码的参数名称，默认：page
						,limitName: 'size' //每页数据量的参数名，默认：limit
					}
					,parseData: function(res) { //res 即为原始返回的数据
						return {
							"code": res.code, //解析接口状态
							"msg": res.msg, //解析提示文本
							"count": res.data.total, //解析数据长度
							"data": res.data.records //解析数据列表
						}
					}
					,cols: [[ //表头
						{type:'checkbox'}
						,{field: 'username', title: '用户名'}
						,{field: 'mobile', title: '手机号'}
						,{field: 'enabled', title: '账号可用',templet:function (d) {
								if (d.enabled==0) return "可用";
								if(d.enabled==1) return "禁用";
							}}
						,{field: 'email', title: '邮箱'}
						,{field: 'insertTime', title: '创建时间',templet:function (d) {
							return	dateToStr(d.insertTime);
							}}
						,{field:'sex', title:'操作', templet: '#barDemo', unresize: true}
					]]
					,page:true //开启分页
				});

				//监听工具条
				table.on('tool(demo)', function(obj){
					var data1 = obj.data;
					if(obj.event === 'del'){
						layer.confirm('真的删除行么', function(index){
							delBatch(data1.id+",","/sysUser/delBatchByIds","table1");
							layer.close(index);
						});
					} else if(obj.event === 'edit'){
						console.log(data1);
						sessionStorage.setItem("editRowData",JSON.stringify(data1));
						WeAdminShow('修改用户','./add.html?act=edit');
					}
				});

				/**
				 * 提交查询条件后重新加载表格
				 */
				$('#search1').on('click', function(){
					var getForm = GetForm("FirstForm");
					//执行重载
					table.reload('table1', {
						page: {
							current: 1 //重新从第 1 页开始
						}
						, where: getForm
						, url:requrl//后台做模糊搜索接口路径
						, method: 'post'
					});
					return false;//false：阻止表单跳转  true：表单跳转
				});


				var active = {
					delBatch: function(){ //获取选中数据
						var checkStatus = table.checkStatus('table1')
								,data = checkStatus.data;
						var ids="";
						for (var o in data){
							ids+=data[o].id+",";
						}
						delBatch(ids,"/sysUser/delBatchByIds","table1");
					}
					,addEle: function(){ //获取选中数目
						WeAdminShow('添加用户','./add.html?act=add');
					}
				};

				$('.demoTable .layui-btn').on('click', function(){
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
			});
		</script>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
	</body>

</html>